package com.fram.service.admin.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fram.bean.admin.user.response.UserWithdrawResponse;
import com.fram.bean.admin.user.response.WithdrawDetailResponse;
import com.fram.bean.sys.PageBean;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.exception.ProValiDataException;
import com.fram.entity.UserWithdrawCashList;
import com.fram.mapper.UserWithdrawCashListMapper;
import com.fram.service.admin.WithdrawalService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class WithdrawalServiceImpl implements WithdrawalService{
	
	@Autowired
	private UserWithdrawCashListMapper userWithdrawCashListMapper;
//	@Autowired
//	private DistributorFarmMapper distributorFarmMapper;
	
	@Override
	public PageInfo<UserWithdrawResponse> list(PageBean<UserWithdrawCashList> request) throws ProException {
		PageHelper.startPage(request.getPageNum(), request.getPageSize());
		List<UserWithdrawResponse> list = userWithdrawCashListMapper.listForAdmin(request.getParam());
		if(list == null || list.size() == 0) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return new PageInfo<>(list);
	}

	@Override
	public void update(UserWithdrawCashList request) throws ProException {
		System.out.println(""+request);
		if(userWithdrawCashListMapper.updateByPrimaryKeySelective(request)<=0){
			throw new ProValiDataException(ErrCode.FAIL.getReturnCode(), ErrCode.FAIL.getReturnMsg());
		}
	}

	@Override
	public WithdrawDetailResponse detail(Long id) throws ProException {
		WithdrawDetailResponse cash=userWithdrawCashListMapper.detailForAdmin(id);
		if(cash == null) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return cash;
	}
}
